package org.theSeed.springDatasouceProp.contract.impl;

import cn.hutool.core.util.ObjectUtil;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.theSeed.base.exp.ServiceExp;
import org.theSeed.base.utils.SeedStringUtil;
import org.theSeed.springDatasouceProp.contract.BaseDataSourceAddAware;
import org.theSeed.springDatasouceProp.pojo.prop.SeedDataSourceProp;

import javax.sql.DataSource;
import java.util.Map;

/**
 * 复杂数据源添加实现
 */
@Slf4j
public class BaseDataSourceAddAwareImpl implements BaseDataSourceAddAware {
    public BaseDataSourceAddAwareImpl(SeedDataSourceProp seedDataSourceProp, String linkName, DataSource ds) {
        this.seedDataSourceProp = seedDataSourceProp;
        this.linkName = linkName;
        this.ds = ds;
    }

    private SeedDataSourceProp seedDataSourceProp;

    @Getter
    private String linkName;

    @Getter
    private DataSource ds;

    @Override
    public void addNameDataSource(){
        if (!ObjectUtil.isNull(seedDataSourceProp.getDataSourceMapComplex().put(linkName,ds))){
            throw new ServiceExp(SeedStringUtil.concatStr("名称为",linkName,"复杂数据源添加失败"));
        }
        log.info("名称为{}复杂数据源添加成功",linkName);
    }
}
